package com.hsnn.medstgmini.settlement.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hsnn.medstgmini.Constants;
import com.hsnn.medstgmini.settlement.model.SetAcctInfo;
import com.hsnn.medstgmini.settlement.service.BankAcctInfoManager;
import com.hsnn.medstgmini.sys.model.SysUser;
import com.hsnn.medstgmini.util.Pagination;

/**
 * 
 * @author 言科
 * @category 省药品采购中心  账户信息
 * @date  2015年7月22日
 */
@Controller
@RequestMapping("/acctInfoCore")
public class AcctInfoCoreController {
	
	private static final Logger log = Logger
			.getLogger(AcctInfoCoreController.class);

	@Autowired
	private BankAcctInfoManager bankAcctInfoManager;

	@Autowired
	private HttpServletRequest request;

	@Autowired
	private HttpSession session;

	/**
	 * 
	 *@category 获取当前登陆人信息
	 *@author 言科
	 *@date 2015年7月22日
	 *SysUser
	 */
	public SysUser getUser() {
		return (SysUser) session.getAttribute(Constants.USERINFO);
	}

	/**
	 * 
	 *@category 跳转到药品采购中心账户信息页面
	 *@author 言科
	 *@date 2015年7月22日
	 *String
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/toAcctInfoCore")
	public String toAcctInfoBureau(Model model) {
		Pagination page = new Pagination(request);
		SysUser user = getUser();
		// 查询帐户信息
		SetAcctInfo setAcctInfo = bankAcctInfoManager.getAcctInfo(user);
		model.addAttribute("setAcctInfo", setAcctInfo);

		// 查询银行卡信息
		bankAcctInfoManager.getBankAcctInfoList(page, null, user);
		List<Map<String, Object>> bankAcctList = (List<Map<String, Object>>) page
				.getRows();
		Map<String, Object> bankAcctInfo = null;
		if (bankAcctList != null && !bankAcctList.isEmpty()) {
			bankAcctInfo = bankAcctList.get(0);
		}
		model.addAttribute("bankAcctInfo", bankAcctInfo);

		// 查询开户行列表
		List<Map<String, String>> bankList = bankAcctInfoManager.getBankList();
		model.addAttribute("bankList", bankList);

		return "/settle/bankAcctInfoCore";
	}

}
